/*
 * Text-to-speech will only work if the file
 * connectgui\connect\freetts-1.2\speech.properties
 * is copied to C:\Program Files\Java\jre6\lib
 */

package load.io;
import core.*;
import com.sun.speech.freetts.Voice;
import com.sun.speech.freetts.VoiceManager;

/**
 * Based on the demo applications at http://freetts.sourceforge.net
 * @author Ben
 */
public class TextToSpeech  extends StdNode {
    private DispatcherPort stopped = new DispatcherPort();

    private TriggerPort speak = new TriggerPort() {
        @Override
        public void callInternal() {
            final String VOICE_NAME = "kevin16";
            VoiceManager voiceManager = VoiceManager.getInstance();
            Voice helloVoice = voiceManager.getVoice(VOICE_NAME);

            if (helloVoice != null) {
                 helloVoice.allocate();
                 helloVoice.speak((String)text.getValue());
                 helloVoice.deallocate();
                 stopped.callTargets();
            }
        }
    };

    private InPort text = new InPort(Object.class, speak);

    public TextToSpeech() {
        this.autoPutPorts();
    }


}
